#!/usr/bin/python
import math

t=[]
l=[]
for a in range(406,10000):
    s = str(sorted(str(a**3)))    
    l.append(s)
    t.append(s)
l.sort()

for i in l:
    if l.count(i) == 5: break

print (t.index(i)+406)**3
